package com.kgcx.system.controller;

import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.system.domain.AppVersion;
import com.kgcx.system.service.AppVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 吴刚林
 * @date 2017/11/29
 */
@Api(description = "app版本接口", tags = "app版本接口")
@RestController
@RequestMapping("appversion")
public class AppVersionController extends BaseController {

    @Autowired
    private AppVersionService appVersionService;

    @ApiOperation(value = "新增app版本", httpMethod = "POST", notes = "这是用来新增app版本的接口")
    @PostMapping("addAppVersion")
    public ReturnData addAppVersion(@RequestBody AppVersion appVersion) {
        appVersionService.addAppVersion(appVersion);
        return new ReturnData<>();
    }

    @ApiOperation(value = "查询app版本", httpMethod = "GET", notes = "这是用来查询app版本的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "app版本id", required = true, paramType = "query", dataType = "long", dataTypeClass = Long.class),
    })
    @GetMapping("getAppVersion")
    public ReturnData<AppVersion> getAppVersion(@RequestParam Long kid) {
        return new ReturnData<>(appVersionService.getAppVersion(kid));
    }

    @ApiOperation(value = "查询app版本", httpMethod = "GET", notes = "这是用来查询app版本的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序,sql格式", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
    })
    @GetMapping("getAppVersionList")
    public ReturnData<List<AppVersion>> getAppVersionList() {
        return new ReturnData<>(appVersionService.getAppVersionList(getRequestData()));
    }

    @ApiOperation(value = "查询app最新版本", httpMethod = "GET", notes = "这是用来查询app最新版本的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型，1=android司机端,2=android用户端,3=ios司机端,4=ios用户端", required = true, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
    })
    @GetMapping("getLastAppVersion")
    public ReturnData<AppVersion> getLastAppVersion(@RequestParam Integer type) {
        return new ReturnData<>(appVersionService.getLastAppVersion(type));
    }
}
